// pages/my/my.js
import Dialog from '@vant/weapp/dialog/dialog';
Page({
  data: {
    // avatarUrl: "/static/img/头像.jpg",
    myphUrl: "/static/img/头像.jpg",
    userDesc: "这个人很懒，什么也没有留下",
    points: 1,
    coupons: 1,
    collections: 1,
    activities: 2,
    turnover: 0.03
  },
  handleAllOrders() {
    // 处理全部订单点击逻辑，比如跳转到全部订单页面
    wx.navigateTo({
      url: '/pages/allOrders/allOrders'
    });
  },
  handlePendingPayment() {
    // 处理待付款订单点击逻辑
    wx.navigateTo({
      url: '/pages/pendingPayment/pendingPayment'
    });
  },
  handlePendingUse() {
    // 处理待使用订单点击逻辑
    wx.navigateTo({
      url: '/pages/pendingUse/pendingUse'
    });
  },
  handleEvaluate() {
    // 处理评价订单点击逻辑
    wx.navigateTo({
      url: '/pages/evaluate/evaluate'
    });
  },
  handleRefund() {
    // 处理退款订单点击逻辑
    wx.navigateTo({
      url: '/pages/refund/refund'
    });
  },
  handleHome() {
    // 处理首页点击逻辑
    wx.switchTab({
      url: '/pages/home/home'
    });
  },
  handleMyStore() {
    // 处理我的店铺点击逻辑
    wx.switchTab({
      url: '/pages/myStore/myStore'
    });
  },
  handleActivities() {
    // 处理活动点击逻辑
    wx.switchTab({
      url: '/pages/activities/activities'
    });
  },
  handleStoreDynamic() {
    // 处理店铺动态点击逻辑
    wx.switchTab({
      url: '/pages/storeDynamic/storeDynamic'
    });
  },
  handlePersonalCenter() {
    // 处理个人中心点击逻辑（一般可忽略，因为已经在当前页面）
  },
  onShow() {
    let userId = wx.getStorageSync('id');
    console.log("userId",userId);
    if(userId){

    }else{
      Dialog.confirm({
        title: '系统提示',
        message: '用户未登录，需要登陆后访问',
      })
        .then(() => {
          // on confirm
          this.wxLogin();
          })
        .catch(() => {
          // on cancel
          console.log("取消了");
          this.goHome();
        });
      }
    },
    wxLogin(){
      wx.login({
        success: (res) => {
          console.log("登录获取",res.code);
          this.sendCode();
        },
        fail:(res)=>{
          this.goHome();
        }
      })
    },
    sendCode(code){
      wx.request({
        url: `http://192.168.0.109:80/login/wechatLogin/${code}`,
        method: "post",
        success:(data)=>{
          console.log("成功",data)
        }
      })
  },
     goHome(){
       wx.switchTab({
         url: '/pages/index/index',
       })
     }

})